/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.sigawe.SIASDIT.ProgUtama;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sigawe.SIASDIT.dao.db.DBConnection;

/**
 *
 * @author yoje
 */
public class ManageDatabase {

    private Connection connection;
    ResultSet set = null;
    private String sql = "select *from user";
    PreparedStatement pStatement = null;
    PreparedStatement psql = null;
    Connection koneksi = null;

    public ManageDatabase() {
        try {

            connection = DBConnection.getInstance().getCon();
        } catch (SQLException ex) {
            Logger.getLogger(ManageDatabase.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public String getMataPelajaran(String ikode) throws SQLException {
        PreparedStatement psqlMP = null;
        ResultSet MPset = null;
        psqlMP = connection.prepareStatement("select *from kelmp where idkelmp = ?");
        psqlMP.setString(1, ikode);
        MPset = psqlMP.executeQuery();
        MPset.last();
        if (MPset.getRow() == 0) {
            return "kode Mata Pelajaran tidak ada";
        } else {
            return MPset.getString("kelmp");
        }
    }

    public String getAspekNilai(String ikode) throws SQLException {
        PreparedStatement psqlMP = null;
        ResultSet MPset = null;
        psqlMP = connection.prepareStatement("select *from aspek_nilai where id_aspek = ?");
        psqlMP.setString(1, ikode);
        MPset = psqlMP.executeQuery();
        MPset.last();
        if (MPset.getRow() == 0) {
            return "kode Mata Pelajaran tidak ada";
        } else {
            return MPset.getString("aspek_penilaian");
        }
    }

    public String getkodepribadi(String ikode) throws SQLException {
        PreparedStatement psqlMP = null;
        ResultSet MPset = null;
        psqlMP = connection.prepareStatement("select *from kodeprbd where kode_pribadi = ?");
        psqlMP.setString(1, ikode);
        MPset = psqlMP.executeQuery();
        MPset.last();
        if (MPset.getRow() == 0) {
            return "kode Mata Pelajaran tidak ada";
        } else {
            return MPset.getString("kepribadian");
        }
    }

    public String getkodesurat(String ikode) throws SQLException {
        PreparedStatement psqlMP = null;
        ResultSet MPset = null;
        psqlMP = connection.prepareStatement("select *from det_quran where id_detqur = ?");
        psqlMP.setString(1, ikode);
        MPset = psqlMP.executeQuery();
        MPset.last();
        if (MPset.getRow() == 0) {
            return "kode Nama Surat tidak ada";
        } else {
            return MPset.getString("nama_surat");
        }
    }

    public String getkodebiaya(String ikode) throws SQLException {
        PreparedStatement psqlMP = null;
        ResultSet MPset = null;
        psqlMP = connection.prepareStatement("select *from detail_biaya where id_biaya = ?");
        psqlMP.setString(1, ikode);
        MPset = psqlMP.executeQuery();
        MPset.last();
        if (MPset.getRow() == 0) {
            return "kode Mata Pelajaran tidak ada";
        } else {
            return MPset.getString("detail_biaya");
        }
    }

    public String getnNilai(String inis, String ikelas, String ismtr) throws SQLException {
        List<String> aspek = new ArrayList<String>();
        List<String> nilai = new ArrayList<String>();
        String text = "Nilai Raport ";
        int countPel = 0;
        psql = connection.prepareStatement("SELECT nilai, n.idkelmp, m.induk_siswa, m.semester, s.semester, s.thnajaran, m.kelas FROM nrapot n, siswa sw, master_raport m, kelmp kp, kelas k, smt s WHERE n.id_raport = m.id_raport and m.induk_siswa = sw.induk_siswa and n.IdkelMP = kp.IdkelMP and m.kelas = k.kelas and m.semester = s.idsmt and m.induk_siswa = ? and m.kelas = ? and s.semester = ? ");
        psql.setString(1, inis);
        psql.setString(2, ikelas);
        psql.setString(3, ismtr);
        set = psql.executeQuery();
        set.last();
        countPel = set.getRow();
        System.out.print(countPel);
        if (set.getRow() != 0) {
            set.first();
            text += getNamaSiswa(inis) + " kelas " + ikelas + " semester " + ismtr + " adalah: ";
            for (int i = 0; i < set.getRow(); i++) {
                text += getMataPelajaran(set.getString("idkelmp")) + " " + set.getString("nilai") + ". ";
                set.next();
            }
            return text;
        } else {
            return "Maaf, Data yang anda masukkan tidak sesuai dengan DATABASE";
        }
    }

    public String getUts(String inis, String ikelas, String ismtr) throws SQLException {
        List<String> aspek = new ArrayList<String>();
        List<String> nilai = new ArrayList<String>();
        String text = "Nilai uts ";
        int countPel = 0;
        psql = connection.prepareStatement("SELECT kp.idkelmp, u.nilai, m.induk_siswa, m.semester, s.semester, s.thnajaran, m.kelas FROM uts u, siswa sw, master_raport m, kelmp kp, kelas k, smt s WHERE u.id_raport = m.id_raport and m.induk_siswa = sw.induk_siswa and u.IdkelMP = kp.IdkelMP and m.kelas = k.kelas and m.semester = s.idsmt and m.induk_siswa = ? and m.kelas = ? and s.semester = ? ");
        psql.setString(1, inis);
        psql.setString(2, ikelas);
        psql.setString(3, ismtr);
        set = psql.executeQuery();
        set.last();
        countPel = set.getRow();
        System.out.print(countPel);
        if (set.getRow() != 0) {
            set.first();
            text += getNamaSiswa(inis) + " kelas " + ikelas + " semester " + ismtr + " adalah: ";
            for (int i = 0; i < set.getRow(); i++) {
                text += getMataPelajaran(set.getString("idkelmp")) + " " + set.getString("nilai") + ". ";
                set.next();
            }
            return text;
        } else {
            return "Maaf, Data yang anda masukkan tidak sesuai dengan DATABASE";
        }
    }

    public String getUas(String inis, String ikelas, String ismtr) throws SQLException {
        List<String> aspek = new ArrayList<String>();
        List<String> nilai = new ArrayList<String>();
        String text = "Nilai uas ";
        int countPel = 0;
        psql = connection.prepareStatement("SELECT kp.idkelmp, u.nilai, m.induk_siswa, m.semester, s.semester, s.thnajaran, m.kelas FROM uas u, siswa sw, master_raport m, kelmp kp, kelas k, smt s WHERE u.id_raport = m.id_raport and m.induk_siswa = sw.induk_siswa and u.IdkelMP = kp.IdkelMP and m.kelas = k.kelas and m.semester = s.idsmt and m.induk_siswa = ? and m.kelas = ? and s.semester = ? ");
        psql.setString(1, inis);
        psql.setString(2, ikelas);
        psql.setString(3, ismtr);
        set = psql.executeQuery();
        set.last();
        countPel = set.getRow();
        System.out.print(countPel);
        if (set.getRow() != 0) {
            set.first();
            text += getNamaSiswa(inis) + " kelas " + ikelas + " semester " + ismtr + " adalah: ";
            for (int i = 0; i < set.getRow(); i++) {
                text += getMataPelajaran(set.getString("idkelmp")) + " " + set.getString("nilai") + ". ";
                set.next();
            }
            return text;
        } else {
            return "Maaf, Data yang anda masukkan tidak sesuai dengan DATABASE";
        }
    }

    public String getNHarian(String inis, String ikelas, String ismtr, String itype) throws SQLException {
        List<String> aspek = new ArrayList<String>();
        List<String> nilai = new ArrayList<String>();
        String text = "Nilai Harian ";
        int countPel = 0;
        psql = connection.prepareStatement("SELECT kp.idkelmp, nh.nilai, nh.type, m.induk_siswa, m.semester, s.semester, s.thnajaran, m.kelas FROM nilai_harian nh, siswa sw, master_raport m, kelmp kp, kelas k, smt s WHERE nh.id_raport = m.id_raport and m.induk_siswa = sw.induk_siswa and nh.IdkelMP = kp.IdkelMP and m.kelas = k.kelas and m.semester = s.idsmt and m.induk_siswa = ? and m.kelas = ? and s.semester = ? and nh.type = ?");
        psql.setString(1, inis);
        psql.setString(2, ikelas);
        psql.setString(3, ismtr);
        psql.setString(4, itype);
        set = psql.executeQuery();
        set.last();
        countPel = set.getRow();
        System.out.print(countPel);
        if (set.getRow() != 0) {
            set.first();
            text += getNamaSiswa(inis) + " kelas " + ikelas + " semester " + ismtr + " adalah: ";
            for (int i = 0; i < set.getRow(); i++) {
                text += getMataPelajaran(set.getString("idkelmp")) + " " + set.getString("nilai") + " ";
                set.next();
            }
            return text;
        } else {
            return "Maaf, Data yang anda masukkan tidak sesuai dengan DATABASE";
        }
    }

    public String getnAbsen(String inis, String ikelas, String ismtr) throws SQLException {
        List<String> aspek = new ArrayList<String>();
        List<String> nilai = new ArrayList<String>();
        String text = "Jumlah Abssensi ";
        int countPel = 0;
        psql = connection.prepareStatement("SELECT m.induk_siswa, ka.id_kode, n.jmlabsen, m.semester, s.semester, s.thnajaran, m.kelas FROM nabsensi n, siswa sw, master_raport m, kelas k, smt s, kode_absen ka WHERE n.id_raport = m.id_raport and m.induk_siswa = sw.induk_siswa and n.id_kode = ka.id_kode and m.kelas = k.kelas and m.semester = s.idsmt and m.induk_siswa = ? and m.kelas = ? and s.semester = ? ");
        psql.setString(1, inis);
        psql.setString(2, ikelas);
        psql.setString(3, ismtr);
        set = psql.executeQuery();
        set.last();
        countPel = set.getRow();
        System.out.print(countPel);
        if (set.getRow() != 0) {
            set.first();
            text += getNamaSiswa(inis) + " kelas " + ikelas + " semester " + ismtr + " adalah: ";
            for (int i = 0; i < set.getRow(); i++) {
                text += getKodeAbsen(set.getString("id_kode")) + " " + set.getString("jmlabsen") + " hari. ";
                set.next();
            }
            return text;
        } else {
            return "Maaf, Data yang anda masukkan tidak sesuai dengan DATABASE";
        }
    }

    public String getKodeAbsen(String kode3) throws SQLException {
        PreparedStatement psqlMP = null;
        ResultSet MPset = null;
        psqlMP = connection.prepareStatement("select *from kode_absen where id_kode = ?");
        psqlMP.setString(1, kode3);
        MPset = psqlMP.executeQuery();
        MPset.last();
        if (MPset.getRow() == 0) {
            return "Jenis Absen Tidak Ditemukan";
        } else {
            return MPset.getString("jenis_absen");
        }
    }

    public String absenharian(String inis, String ikelas, String ismtr, String tgl) throws SQLException {
        List<String> aspek = new ArrayList<String>();
        List<String> nilai = new ArrayList<String>();
        String text = "Absensi harian ";
        int countPel = 0;
        int validabsensi = 0;
        psql = connection.prepareStatement("SELECT m.induk_siswa, ab.tgl, ab.m, ab.s, ab.i, ab.a, m.semester, s.thnajaran, m.kelas FROM absensiswaperkelas ab, siswa sw, master_raport m, kelas k, smt s WHERE ab.id_raport = m.id_raport AND m.induk_siswa = sw.induk_siswa AND m.kelas = k.kelas AND m.semester = s.idsmt AND m.induk_siswa = ? and m.kelas = ? and s.semester = ? and ab.tgl = ? ");
        psql.setString(1, inis);
        psql.setString(2, ikelas);
        psql.setString(3, ismtr);
        psql.setString(4, tgl);
        set = psql.executeQuery();
        set.last();
        countPel = set.getRow();
        System.out.print(countPel);
        if (set.getRow() != 0) {
            set.first();
            text += getNamaSiswa(inis) + " tanggal " + tgl + " adalah: ";
            for (int i = 0; i < set.getRow(); i++) {
                validabsensi = 0;
                validabsensi = set.getInt("ab.m") + set.getInt("ab.s") + set.getInt("ab.i") + set.getInt("ab.a");
                if (validabsensi > 1) {
                    text += "maaf terjadi kesalahan inputan data dari admin";
                } else {
                    if (set.getInt("ab.m") != 0) {
                        text += "masuk";
                    } else if (set.getInt("ab.s") != 0) {
                        text += "sakit";
                    } else if (set.getInt("ab.i") != 0) {
                        text += "izin";
                    } else if (set.getInt("ab.a") != 0) {
                        text += "alfa";
                    } else {
                        text = "Maaf data absensi anda belum di update!!!";
                    }
                }
            }
            return text;
        } else {
            return "Maaf, Data yang anda masukkan tidak sesuai dengan DATABASE";
        }
    }

    public String getNamaSiswa(String kode3) throws SQLException {
        PreparedStatement psqlMP = null;
        ResultSet MPset = null;
        psqlMP = connection.prepareStatement("select *from siswa where induk_siswa = ?");
        psqlMP.setString(1, kode3);
        MPset = psqlMP.executeQuery();
        MPset.last();
        if (MPset.getRow() == 0) {
            return "nama siswa tidak ditemukan";
        } else {
            return MPset.getString("nama");
        }
    }

    public String getNamaguru(String kode2) throws SQLException {
        PreparedStatement psqlMP = null;
        ResultSet MPset = null;
        psqlMP = connection.prepareStatement("select *from guru where nip = ?");
        psqlMP.setString(1, kode2);
        MPset = psqlMP.executeQuery();
        MPset.last();
        if (MPset.getRow() == 0) {
            return "nama guru tidak ditemukan";
        } else {
            return MPset.getString("nama_guru");
        }
    }

    public String getNPribadi(String inis, String ikelas, String ismtr) throws SQLException {
        List<String> kprbd = new ArrayList<String>();
        List<String> nilai = new ArrayList<String>();
        String text = "Nilai Raport Kepribadian ";
        int countPel = 0;
        psql = connection.prepareStatement("SELECT np.kode_pribadi, m.induk_siswa, np.nilai, m.kelas, m.semester, s.semester, s.thnajaran FROM nkepribadian np, siswa sw, kodeprbd k, smt s, kelas kl, master_raport m WHERE m.id_raport = np.id_raport AND np.kode_pribadi = k.kode_pribadi AND m.induk_siswa = sw.induk_siswa AND m.semester = s.idsmt AND m.kelas = kl.kelas AND m.induk_siswa = ? AND m.kelas = ? AND s.semester = ? ");
        psql.setString(1, inis);
        psql.setString(2, ikelas);
        psql.setString(3, ismtr);
        set = psql.executeQuery();
        set.last();
        countPel = set.getRow();
        System.out.print(countPel);
        if (set.getRow() != 0) {
            set.first();
            text += getNamaSiswa(inis) + " semester " + ismtr + " adalah : ";
            for (int i = 0; i < set.getRow(); i++) {
                text += getkodepribadi(set.getString("kode_pribadi")) + " " + set.getString("nilai") + ". ";
                set.next();
            }
            return text;
        } else {
            return "Maaf, Data yang anda masukkan tidak sesuai dengan DATABASE";
        }
    }

    public String gettahfidz(String inis, String ikelas, String ismtr) throws SQLException {
        List<String> surat = new ArrayList<String>();
        List<String> nilai = new ArrayList<String>();
        String text = "Nilai Tahfidzul Qur`an ";
        int countPel = 0;
        psql = connection.prepareStatement("SELECT mr.induk_siswa, rq.id_detqur, rq.nilai, mr.semester, sm.semester, sm.thnajaran, mr.kelas FROM raport_quran rq, siswa sw, master_raport mr, det_quran dq, smt sm, kelas k WHERE dq.id_detqur = rq.id_detqur and rq.id_raport = mr.id_raport and mr.induk_siswa = sw.induk_siswa and mr.semester = sm.idsmt and mr.kelas = k.kelas and sw.induk_siswa = ? and mr.kelas = ? and sm.semester = ? ");
        psql.setString(1, inis);
        psql.setString(2, ikelas);
        psql.setString(3, ismtr);
        set = psql.executeQuery();
        set.last();
        countPel = set.getRow();
        System.out.print(countPel);
        if (set.getRow() != 0) {
            set.first();
            text += getNamaSiswa(inis) + " semester " + ismtr + " adalah : ";
            for (int i = 0; i < set.getRow(); i++) {
                text += getkodesurat(set.getString("id_detqur")) + " " + set.getString("nilai") + ". ";
                set.next();
            }
            return text;
        } else {
            return "Maaf, Data yang anda masukkan tidak sesuai dengan DATABASE";
        }
    }

    public String getbiaya(String inis, String ikelas, String ismtr) throws SQLException {
        List<String> id_biaya = new ArrayList<String>();
        List<String> biaya = new ArrayList<String>();
        String text = "Biaya yang harus ";
        int countPel = 0;
        psql = connection.prepareStatement("SELECT b.induk_siswa, b.id_biaya, b.biaya, b.kelas, s.semester, s.thnajaran FROM biaya b, siswa sw, detail_biaya db, smt s, kelas kl WHERE b.id_biaya = db.id_biaya and b.induk_siswa = sw.induk_siswa and b.idsmt = s.idsmt and b.kelas = kl.kelas and b.induk_siswa = ?  and b.kelas = ? and s.semester = ? ");
        psql.setString(1, inis);
        psql.setString(2, ikelas);
        psql.setString(3, ismtr);
        set = psql.executeQuery();
        set.last();
        countPel = set.getRow();
        System.out.print(countPel);
        if (set.getRow() != 0) {
            set.first();
            text += getNamaSiswa(inis) + " bayarkan semester " + ismtr + " adalah : ";
            for (int i = 0; i < set.getRow(); i++) {
                text += getkodebiaya(set.getString("id_biaya")) + " " + set.getString("biaya") + ". ";
                set.next();
            }
            return text;
        } else {
            return "Maaf, Data yang anda masukkan tidak sesuai dengan DATABASE";
        }
    }

    public String ranking(String ikelas, String ismtr) throws SQLException {
        List<String> id_biaya = new ArrayList<String>();
        List<String> biaya = new ArrayList<String>();
        String text = "Ranking Kelas  ";
        int countPel = 0;
        psql = connection.prepareStatement("select rk.induk_siswa, rk.kelas, rk.idsmt, sm.semester, sm.thnajaran, rk.ranking from ranking rk, siswa sw, kelas kl, smt sm where rk.induk_siswa = sw.induk_siswa and rk.kelas = kl.kelas and rk.idsmt = sm.idsmt and rk.kelas = ? and sm.semester = ? ");
        psql.setString(1, ikelas);
        psql.setString(2, ismtr);
        set = psql.executeQuery();
        set.last();
        countPel = set.getRow();
        System.out.print(countPel);
        if (set.getRow() != 0) {
            set.first();
            text += ikelas + " semester " + ismtr + " adalah : ";
            for (int i = 0; i < set.getRow(); i++) {
                text += getNamaSiswa(set.getString("induk_siswa")) + " ranking " + set.getString("ranking") + ". ";
                set.next();
            }
            return text;
        } else {
            return "Maaf, Data yang anda masukkan tidak sesuai dengan DATABASE";
        }
    }

    public int iBiaya(String kode1, String kode2, String kode3, String kode4) throws SQLException {
        PreparedStatement psqlMP = null;
        ResultSet MPset = null;
        psqlMP = connection.prepareStatement("SELECT SUM(biaya) AS total_biaya FROM biaya WHERE induk_siswa = ? and kelas = ? and idsmt = ? and bulan = ? ");
        psqlMP.setString(1, kode1);
        psqlMP.setString(2, kode2);
        psqlMP.setString(3, kode3);
        psqlMP.setString(4, kode4);
        MPset = psqlMP.executeQuery();
        MPset.last();
        if (MPset.getRow() == 0) {
            return MPset.getInt("error");
        } else {
            return MPset.getInt("total_biaya");
        }
    }

    public int iBayar(String kode1, String kode2) throws SQLException {
        PreparedStatement psqlMP = null;
        ResultSet MPset = null;
        psqlMP = connection.prepareStatement("SELECT SUM(bayar) AS total_bayar FROM bayar WHERE induk_siswa = ? and bulan = ? ");
        psqlMP.setString(1, kode1);
        psqlMP.setString(2, kode2);
        MPset = psqlMP.executeQuery();
        MPset.last();
        if (MPset.getRow() == 0) {
            return MPset.getInt("error");
        } else {
            return MPset.getInt("total_bayar");
        }
    }
    String SqlBayar = null;
    String SqlBiaya = null;
    String All = null;

    public String getCekBayar(String inis, String iKelas, String iSmtr, String ibulan) throws SQLException {
        String text = "Layanan cek pembayaran,";
        int countPel = 0;
        psql = connection.prepareStatement("SELECT sw.induk_siswa, kl.kelas, sm.idsmt, sm.semester, sm.thnajaran, br.bulan, ba.bulan FROM siswa sw, kelas kl, smt sm, bayar br, biaya ba where sw.induk_siswa = ? and kl.kelas = ? and sm.semester = ? and br.bulan = ? ");
        psql.setString(1, inis);
        psql.setString(2, iKelas);
        psql.setString(3, iSmtr);
        psql.setString(4, ibulan);
        set = psql.executeQuery();
        set.last();
        if (set.getRow() != 0) {
            set.first();
            if (iBayar(set.getString("induk_siswa"), set.getString("bulan")) >= iBiaya(set.getString("induk_siswa"), set.getString("kelas"), set.getString("idsmt"), set.getString("bulan"))) {
                text += getNamaSiswa(inis) + " dinyatakan LUNAS pembayaran bulan " + ibulan + ".";
                set.next();
            } else {
                text += getNamaSiswa(inis) + " BELUM LUNAS pembayaran bulan " + ibulan + ", total kekurangan Rp." + (iBiaya(set.getString("induk_siswa"), set.getString("kelas"), set.getString("idsmt"), set.getString("bulan")) - iBayar(set.getString("induk_siswa"), set.getString("bulan")));
            }
            return text;
        } else {
            return "maaf, anda belum melakukan pembayaran";
        }
    }

    public void inputDataBayar(String iNis, String iNorec, String ibulan, String iBayar) throws SQLException {

        int countPel = 0;
        psql = connection.prepareStatement("insert into bayar(induk_siswa,norec,bulan,bayar) values(?,?,?,?)");
        psql.setString(1, iNis);
        psql.setString(2, iNorec);
        psql.setString(3, ibulan);
        psql.setString(4, iBayar);
        psql.execute();

        System.out.println("Data Berhasil DiUpdate");
//            return text;
    }

    public boolean inputDataUser(String iUser, String ipass, String itelp, String iposisi) {
        try {

            PreparedStatement psqlMP = null;
            ResultSet MPset = null;
            psqlMP = connection.prepareStatement("insert into user(user,pass,telp,status,posisi) values(?,?,?,false,?)");
            psqlMP.setString(1, iUser);
            psqlMP.setString(2, ipass);
            psqlMP.setString(3, itelp);
            psqlMP.setString(4, iposisi);
            psqlMP.execute();


            return true;
        } catch (SQLException ex) {
            Logger.getLogger(ManageDatabase.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }

    }

    public boolean isUserInDatabase(String iNomer) {
        int jumlah = 0;

        try {
            psql = connection.prepareStatement("select *from user where telp =?");
            psql.setString(1, iNomer);
            set = psql.executeQuery();
            set.last();
            jumlah = set.getRow();


            if (jumlah >= 1) {
                return true;
            } else {
                return false;
            }
        } catch (SQLException ex) {
            Logger.getLogger(ManageDatabase.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    public boolean isUsernameInDatabse(String iusername) {
        int jumlah = 0;
        System.out.print(iusername);
        try {
//            psql = koneksi.prepareStatement("select *from user where user =hunter");
//            psql.setString(1, iusername);
//            set = psql.executeQuery();
//            set.last();

            PreparedStatement psqlMP = null;
            ResultSet MPset = null;
            psqlMP = connection.prepareStatement("select *from user where user =?");
            psqlMP.setString(1, iusername);
            MPset = psqlMP.executeQuery();
            MPset.last();

            jumlah = MPset.getRow();
            System.out.print(jumlah);
            if (jumlah >= 1) {
                return true;
            } else {
                return false;
            }
        } catch (SQLException ex) {
            Logger.getLogger(ManageDatabase.class.getName()).log(Level.SEVERE, null, ex);
            return false;

        }
    }

    public boolean isActiveUser(String iNilai) {
        boolean status;
        try {


            PreparedStatement psqlMP = null;
            ResultSet MPset = null;
            psqlMP = connection.prepareStatement("select *from user where telp =? and status = true");
            psqlMP.setString(1, iNilai);
            MPset = psqlMP.executeQuery();
            MPset.last();


            if (MPset.getRow() == 1) {
                return true;
            } else {
                return false;
            }
        } catch (SQLException ex) {
            Logger.getLogger(ManageDatabase.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }

    }

    public boolean ChangeUserStatus(String iNomer, boolean istatus) {
        try {

            PreparedStatement psqlMP = null;
            ResultSet MPset = null;
            psqlMP = connection.prepareStatement("UPDATE user SET status = true where telp = ?");
            //   psqlMP.setBoolean(1, istatus);
            psqlMP.setString(1, iNomer);
            psqlMP.executeUpdate();

            return true;
        } catch (SQLException ex) {
            Logger.getLogger(ManageDatabase.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }

    }
}